/*********************************************************************
 *                                                                   *
 *  Js Css Minifier ( JsCssMin )                                     *
 *  Author: Igor Kanshyn                                             *
 *  Copyright (c) 2009, Igor Kanshyn. All rights reserved.           *
 *                                                                   *
 *  JsCssMin is released under the Apache Software License.          *
 *  See LICENSE.txt for more details.                                *
 *                                                                   *
 *********************************************************************/

package org.grenader.jscssmin.model;

import static org.junit.Assert.*;
import org.junit.Test;

/**
 * <p>Product: JsCssMin ( JavaScript and CSS Minifier )<br>
 * Author: Igor Kanshyn (grenader).
 * </p>
 * Date: Apr 26, 2009
 */
public class CSSResourceTestCase {
    @Test
    public void testGetFileName_odd() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" href=\"my my.css type=\"text/css\" />");
        assertEquals("my my.css type=", resource.extractFileName());
    }

    @Test
    public void testGetFileName_noQuote() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" href=\"my my.CSS\" type=\"text/css\" />");
        assertEquals("my my.CSS", resource.extractFileName());
    }

    @Test
    public void testGetFileName_doubleQuote() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" href=\"my my.css\" type=\"text/css\" />");
        assertEquals("my my.css", resource.extractFileName());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testGetFileName_error() {
        CSSResource resource = new CSSResource("<script src=\"js1 js2 v1.js\" type=\"text/javascript\"></script>");
        assertEquals("my my.css", resource.extractFileName());
    }

    @Test
    public void testGetFileName_doubleQuote2() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" href=\"my my.css\" type=\"text/css\" />");
        assertEquals("my my.css", resource.getFileName());
    }

    @Test
    public void testGetFileName_singleQuote() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" href=\"my my.css\" type=\"text/css\" />");
        assertEquals("my my.css", resource.getFileName());
    }

    @Test
    public void testGetFileName_singleQuote2() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" href=\"my my.css\" type=\"text/css\" />");
        assertEquals("my my.css", resource.getFileName());
    }

    @Test
    public void testGetFileName_singleQuote3() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" HREF=\"my my.css\" type=\"text/css\" />");
        assertEquals("my my.css", resource.getFileName());
    }

    @Test
    public void testGetFileName_singleQuote4() {
        CSSResource resource = new CSSResource("<link rel=\"stylesheet\" hREf=\"my my.css\" type=\"text/css\" />");
        assertEquals("my my.css", resource.getFileName());
    }

    @Test
    public void testGetFileName_equals() {
        CSSResource resource1 = new CSSResource("<link rel=\"stylesheet\" hREf=\"my.css\" type=\"text/css\" />");
        CSSResource resource2 = new CSSResource("<link rel=\"stylesheet\" hREf=\"my.css\" type=\"text/css\" />");

        assertTrue(resource1.equals(resource1));
        assertTrue(resource1.equals(resource2));
        assertTrue(resource2.equals(resource2));
    }

    @Test
    public void testGetFileName_nonEquals() {
        CSSResource resource1 = new CSSResource("<link rel=\"stylesheet\" hREf=\"my1.css\" type=\"text/css\" />");
        CSSResource resource2 = new CSSResource("<link rel=\"stylesheet\" hREf=\"my2.css\" type=\"text/css\" />");

        assertFalse(resource1.equals(resource2));
        assertFalse(resource2.equals(resource1));
    }

    @Test
    public void testGetFileName_nonEqualsMixTypes1() {
        CSSResource resource1 = new CSSResource("<link rel=\"stylesheet\" hREf=\"my1.css\" type=\"text/css\" />");
        JavaScriptResource resource2 = new JavaScriptResource("<script type=\"text/javascript\" src=\"js1.js\"></script>");

        assertFalse(resource1.equals(resource2));
        assertFalse(resource2.equals(resource1));
    }

}

